/*
 * @Description:
 * @Version: 2.0
 * @Autor: ruog__
 * @Date: 2024-04-17 16:27:49
 * @LastEditors: ruog__
 * @LastEditTime: 2024-04-18 14:10:50
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#include <mtd/mtd-abi.h>
#include <time.h>
#include <iostream>
#include "common.h"
using namespace std;

void *spi1_addr = NULL;

void spi_reset()
{
    u32 value = Xil_read(spi1_addr + SPI1_GCR);
    value |= 1 << 31;
    Xil_write(spi1_addr + SPI1_GCR, value);
}

void spi_config()
{
    u32 value = 0x83;//0b10000011
    Xil_write(spi1_addr + SPI1_GCR, value);
}

#if 0
int main()
{
    int gpioMapFd = -1, spi1MapFd = -1;
    void *gpio_addr = devm_map(GPIO_BASE_ADDR, MMAP_SIZE, &gpioMapFd);
    if (gpio_addr == NULL)
    {
        printf("mram_test: mmap fail!\n");
        return -1;
    }
    spi1_addr = devm_map(SPI1_BASE_ADDR, MMAP_SIZE, &spi1MapFd);
    if (spi1_addr == NULL)
    {
        printf("spi1_addr: mmap fail!\n");
        return -1;
    }
    u32 value = 0;

    spi_reset();
    spi_config();

    return 0;
}

#endif